package gant.ext

import org.codehaus.gant.GantBinding
import org.codehaus.gant.GantBuilder
import org.junit.BeforeClass
import org.junit.Test

/**
 */
class GantActivatorTest {

    def foo = new Foo()

    @Test
    void testSettingBinding() {
        new GantActivator(script: foo).addBindingToScript()
        assert foo.binding instanceof GantBinding
    }

    @Test
    void testRunCountOfFoo() {
        foo.run()
        assert 1 == foo.runCount
    }

    @Test
    void "any loaded class should exist"() {
        assert GantActivator.classExists("java.lang.String")
    }

    @Test
    void "any class not loaded should not exist" () {
        assert !GantActivator.classExists("foo.baz.Bar")
    }

    @Test
    void "logback is on the classpath"() {
        assert GantActivator.logbackIsOnTheClassPath()
    }

    @Test
    void "GantActivator.class is on the classpath" () {
        assert GantActivator.resourceIsOnClassPath("gant/ext/GantActivator.class")
    }

    @Test
    void "logback is not configured"() {
        assert GantActivator.logbackIsNotConfigured()
    }
}

class Foo extends Script {
    int runCount = 0

    @Override
    Object run() {
        runCount++
        GantActivator.activateGant(this)
        target(main: "default script") {
            echo(message: "i ran")
            //let's make sure the log property has been set
//            log.error("blah")
        }

        setDefaultTarget main
        executeTargets()
    }
}